/**
 * @Project Name:blog-business-service
 * @Package Name:cn.hoofungson.blog.business.service.provider.controller.article
 * @Since JDK 1.8
 */

package cn.hoofungson.blog.business.service.provider.controller.article;

import cn.hoofungson.blog.business.service.interfaces.domain.dto.article.ArticleDTO;
import cn.hoofungson.blog.business.service.provider.service.article.ArticleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @Description: ArticleController
 * @Author 胡松 hoofungson@163.com
 * @Date 2020-03-24 18:56
 * @Version V1.0
 */
@Slf4j
@RequestMapping("/service/article")
@RestController
public class ArticleServiceController {

    @Autowired
    private ArticleService articleService;

    @GetMapping
    public ResponseEntity<ArticleDTO> get() {
        ArticleDTO articleDTO = new ArticleDTO();
        articleDTO.setId(System.currentTimeMillis());
        articleDTO.setTitle("第一篇测试文章");
        articleDTO.setShortTitle("测试文章");
        articleDTO.setHtmlContent("这是一篇测试文章内容！！");
        articleDTO.setCreateTime(new Date());
        articleDTO.setUpdateTime(new Date());
        return new ResponseEntity<>(articleDTO, HttpStatus.OK);
    }

    @GetMapping("/{id}")
    public ResponseEntity<ArticleDTO> get(@PathVariable("id") Long id) {
        ArticleDTO articleDTO = this.articleService.get(id);
        log.info("admin-api获取数据链路, business-service端输出！！");
        return new ResponseEntity<>(articleDTO, HttpStatus.OK);
    }
}
